# -*- coding: utf-8 -*-

"""
* Copyright (C) 2016 GridSafe, Inc.
"""
import json
from apps.wallet import constants
from apps.wallet.models.profile import Profile
from apps.wallet.models.friend import Follow
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from apps.mixin import LoginRequiredMixin

from django.views.generic import TemplateView


def userInfo(request, id):
    """用户信息"""
    context = {}
    user = request.user
    is_owner, loved = 0, 0

    if user.is_authenticated and user.id == int(id):
        is_owner = 1
        user_ = user
    else:
        user_ = Profile.objects.get(pk=id)
    if user.is_authenticated and Follow.objects.filter(user=user, who=id).exists():
        loved = 1  # 是否关注了他
    context['is_owner'] = is_owner
    context['loved'] = loved
    context['id'] = id
    context['us'] = user_
    return render(request, 'user/user.html', context)

@login_required
def homepage(request):
    return render(request, 'app/index.html')

